package com.tian.earth.ui.activity

import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.bottomnavigation.LabelVisibilityMode
import com.tian.earth.R
import com.tian.earth.ui.fragment.SchoolListFragment

/**
 * @author tiansongtao, Email:769001510@qq.com
 * @date 19-6-21 下午2:07
 */
class MainActivity : BaseActivity(){


    lateinit var bottomNavigationView: BottomNavigationView

    val fragments = ArrayList<Fragment>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initView()
        initFragment()
    }

    private fun initFragment() {
        fragments.clear()
        fragments.add(SchoolListFragment())
    }

    private fun initView() {
        bottomNavigationView = findViewById(R.id.bn_main_activity_menu)
        bottomNavigationView.labelVisibilityMode = LabelVisibilityMode.LABEL_VISIBILITY_LABELED
        bottomNavigationView.setOnNavigationItemSelectedListener {
                menuItem -> onNavigationItemSelected(menuItem)
        }
    }

    private fun onNavigationItemSelected(menuItem: MenuItem): Boolean {
        when(menuItem.itemId) {
            R.id.item_main_activity_first -> {
                supportFragmentManager.beginTransaction().
                        add(R.id.main_content_fragment, SchoolListFragment()).commit()
            }
            else -> {}
        }
        return true
    }
}